import type {
  KnowledgeParams,
  KnowledgePage,
  PageParams,
  DoctorPage,
  FollowType,
  TopDep,
  Image,
  ConsultOrderPreParams,
  ConsultOrderPreData,
  PartialConsult,
  Pay,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage
} from './../types/consult'
import { request } from '@/utils/request'
// 获取首页文章列表
export const getKnowledgePage = (params: KnowledgeParams) =>
  request<KnowledgePage>('/patient/home/knowledge', 'GET', params)

// 获取首页医生列表
export const getDoctorPage = (params: PageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', params)

// 关注or取消关注
export const followOrUnFollow = (id: string, type: FollowType = 'doc') =>
  request('/like', 'POST', {
    id,
    type
  })

// 获取一级科室
export const getAllDep = () => request<TopDep[]>('/dep/all')

// 上传图片
export const upLoadImage = (file: File) => {
  // 上传图片 -> formData 对象
  // 1. 创建一个formData对象
  // 2. 将获取到的图片进行添加
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

// 预付款订单信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

// 生成订单
export const createConsultOrder = (params: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', params)

// 订单支付
export const getConsultOrderPayUrl = (params: Pay) =>
  request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)

// 订单详情
export const getOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', {
    orderId
  })

// 根据处方id获取处方图片
export const getPrescriptionPic = (id: string) =>
  request<{ url: string }>(`/patient/consult/prescription/${id}`, 'GET', {
    id
  })

// 评价医生
export const evaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request<{ id: string }>('/patient/order/evaluate', 'POST', data)

// 问诊订单记录
export const getConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

// 取消订单/问诊
export const cancelOrder = (id: string) =>
  request(`/patient/order/cancel/${id}`, 'PUT')

// 删除订单
export const deleteOrder = (id: string) =>
  request(`/patient/order/${id}`, 'DELETE')
